﻿
Partial Class WebForm_SearchControl_SearchEmployeeControl
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.Visible = False
    End Sub

    Protected Sub gv_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv.PageIndexChanging
        Me.gv.PageIndex = e.NewPageIndex
        Me.BindGV()
    End Sub

    Protected Sub gv_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gv.RowCommand
        If e.CommandName = "Select" Then
            Dim rowIndex As Integer = e.CommandArgument
            Me.SelectedUserID = TryCast(Me.gv.Rows(rowIndex).FindControl("lblUserID"), Label).Text
            Me.SelectedUserName = TryCast(Me.gv.Rows(rowIndex).FindControl("lblUserName"), Label).Text
            Me.SelectedOrganizationName = TryCast(Me.gv.Rows(rowIndex).FindControl("lblOrganizationName"), Label).Text
            Me.SelectedUOrganizationID = TryCast(Me.gv.Rows(rowIndex).FindControl("lblUOrganizationID"), Label).Text
            RaiseEvent SelectedIndexChanged(Me, New EventArgs)
        End If
    End Sub

    Protected Sub ddlOrganizationID_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlOrganizationID.Load
        If Not IsPostBack Then
            Me.ddlOrganizationID.DataTextField = "OrganizationName"
            Me.ddlOrganizationID.DataValueField = "UOrganizationID"
            Me.ddlOrganizationID.DataSource = clsAuth.GetDDLDirectOrganizationData()
            Me.ddlOrganizationID.DataBind()
        End If
    End Sub

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        Me.BindGV()
    End Sub
End Class

Partial Class WebForm_SearchControl_SearchEmployeeControl
    Public Sub Show()
        Me.BindGV()
    End Sub

    Private Sub BindGV()
        Dim dat As New clsData
        Dim sql As New MyOrganizationDataFilter

        sql.Length = 0
        sql.AppendFormat("select a.UserID,a.UserName,b.UOrganizationID,b.OrganizationName ")
        sql.AppendFormat(" from InternalUser a inner join OrganizationView b ")
        sql.AppendFormat("on a.UOrganizationID = b.UOrganizationID ")

        sql.AppendFormat(GetWhereSQL())

        Me.gv.DataSource = dat.GetData(sql)
        Me.gv.DataBind()

        Me.Visible = True
        Me.mpSearch.Show()
    End Sub

    Public Function GetWhereSQL() As String
        Dim sql As New MyStringBuilder

        If Me.ddlOrganizationID.SelectedValue <> "" Then
            sql.AppendFormat("and a.UOrganizationID = '{0}' ", Me.ddlOrganizationID.SelectedValue)
        End If

        Return sql.ToString()
    End Function

    Public Property SelectedUserID() As String
        Get
            Return ViewState("SelectedUserID")
        End Get
        Set(ByVal value As String)
            ViewState("SelectedUserID") = value
        End Set
    End Property

    Public Property SelectedUserName() As String
        Get
            Return ViewState("SelectedUserName")
        End Get
        Set(ByVal value As String)
            ViewState("SelectedUserName") = value
        End Set
    End Property

    Public Property SelectedOrganizationName() As String
        Get
            Return ViewState("SelectedOrganizationName")
        End Get
        Set(ByVal value As String)
            ViewState("SelectedOrganizationName") = value
        End Set
    End Property

    Public Property SelectedUOrganizationID() As String
        Get
            Return ViewState("SelectedUOrganizationID")
        End Get
        Set(ByVal value As String)
            ViewState("SelectedUOrganizationID") = value
        End Set
    End Property

    Public Event SelectedIndexChanged(ByVal source As Object, ByVal e As EventArgs)
End Class